package com.hy.mydesktop.client.mvc.core.builder;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.hy.mydesktop.client.component.type.ComponentControllerEnum;
import com.hy.mydesktop.client.component.type.ComponentTypeEnum;
import com.hy.mydesktop.shared.persistence.domain.gxt.GxtComponentControllerMetaNodeModel;
import com.hy.mydesktop.shared.persistence.domain.gxt.GxtComponentMetaNodeModel;
import com.hy.mydesktop.shared.persistence.domain.gxt.constant.ComponentMetaDataConstants;
import com.hy.mydesktop.shared.persistence.domain.gxt.constant.MetaDataConstants;

public class ControllerAndComponentMetaNodeModelCreationTemplate {

	
	public static GxtComponentControllerMetaNodeModel createWindowTemplate(String controllerMetaModelId,
			int leftValue,int rightValue,Map<String, Object> map2) {		
		Map<String, Object> map1=configureMap1(controllerMetaModelId, leftValue, rightValue);
		return WindowBuilderTemplate.createWindowTemplate(map1,map2);				
		//return node;		
	}
	public static GxtComponentControllerMetaNodeModel createWindowTemplate(Map<String, Object> map1,Map<String, Object> map2) {
		return WindowBuilderTemplate.createWindowTemplate(map1,map2);				
		//return node;		
	}
	
	public static GxtComponentControllerMetaNodeModel createContentPanelTemplate(String controllerMetaModelId,
			int leftValue,int rightValue,Map<String, Object> map2) {		
		Map<String, Object> map1=configureMap1(controllerMetaModelId, leftValue, rightValue);
		return ContentPanelBuilderTemplate.createContentPanelTemplate(map1,map2);				
		//return node;		
	}
	
	public static GxtComponentControllerMetaNodeModel createContentPanelTemplate(Map<String, Object> map1,Map<String, Object> map2) {
		return ContentPanelBuilderTemplate.createContentPanelTemplate(map1,map2);
				
		//return node;		
	}
	
	private static Map<String, Object> configureMap1(String controllerMetaModelId,
			int leftValue,int rightValue) {
		Map<String, Object> map1=new HashMap<String, Object>();
		if (controllerMetaModelId==null) {
			throw new RuntimeException("ssssssssssssssssssssss");
		} 
		if (leftValue==0) {
			throw new RuntimeException("ssssssssssssssssssssss");

		}
		if (rightValue==0) {
			throw new RuntimeException("ssssssssssssssssssssss");

		}
		map1.put(MetaDataConstants.LEFT_VALUE, leftValue);
		map1.put(MetaDataConstants.RIGHT_VALUE, rightValue);
		map1.put(MetaDataConstants.COMPONENT_CONTROLLER_METAMODEL_ID, controllerMetaModelId);
		
		return map1;

		
	}
	public static GxtComponentMetaNodeModel removeUnusedProperties(
			GxtComponentMetaNodeModel gxtComponentMetaNodeModel) {
		gxtComponentMetaNodeModel.set(MetaDataConstants.COMPONENT_CONTROLLER_METAMODEL_ID,null);
		return gxtComponentMetaNodeModel;
			
	}
	public static GxtComponentControllerMetaNodeModel buildCommonAttributes(
			GxtComponentControllerMetaNodeModel gxtComponentControllerMetaNodeModel, Map<String, Object> map1) {
		for (String key : map1.keySet()) {
			gxtComponentControllerMetaNodeModel.set(key, map1.get(key));
		}
		if (map1.get(MetaDataConstants.LEFT_VALUE)!=null) {	
			
			gxtComponentControllerMetaNodeModel.setLeftValue((Integer)map1.get(MetaDataConstants.LEFT_VALUE));
		}else {
			throw new RuntimeException("xxxxxxxxxxxxx");
		}
		if (map1.get(MetaDataConstants.RIGHT_VALUE)!=null) {			
			gxtComponentControllerMetaNodeModel.setRightValue((Integer)map1.get(MetaDataConstants.RIGHT_VALUE));
		}else {
			throw new RuntimeException("xxxxxxxxxxxxx");
		}
		/*if (map1.get(MetaDataConstants.COMPONENT_CONTROLLER_METAMODEL_ID)!=null) {	
			String controllerMetaModelId=(String)map1.get(MetaDataConstants.COMPONENT_CONTROLLER_METAMODEL_ID);
			String id="windowController_"+controllerMetaModelId;
			gxtComponentControllerMetaNodeModel.setId(id);
			gxtComponentControllerMetaNodeModel.setControllerMetaNodeModelId(id);

		}else {
			throw new RuntimeException("xxxxxxxxxxxxx");
		}*/
		return gxtComponentControllerMetaNodeModel;
	}

	public static GxtComponentControllerMetaNodeModel createMenuBarTemplate(String controllerMetaModelId,
			int leftValue,int rightValue,Map<String, Object> map2) {		
		Map<String, Object> map1=configureMap1(controllerMetaModelId, leftValue, rightValue);
		return MenuBarBuilderTemplate.createMenuBarBuilderTemplate(map1,map2);				
		//return node;		
	}
	
	public static GxtComponentControllerMetaNodeModel createMenuBarTemplate(
			Map<String, Object> map1, Map<String, Object> map2) {
		
		return MenuBarBuilderTemplate.createMenuBarBuilderTemplate(map1,map2);

	}
	
	public static GxtComponentControllerMetaNodeModel createToolBarTemplate(String controllerMetaModelId,
			int leftValue,int rightValue,Map<String, Object> map2) {		
		Map<String, Object> map1=configureMap1(controllerMetaModelId, leftValue, rightValue);
		return ToolBarBuilderTemplate.createToolBarBuilderTemplate(map1,map2);				
		//return node;		
	}

	public static GxtComponentControllerMetaNodeModel createToolBarTemplate(
			Map<String, Object> map1, Map<String, Object> map2) {
		// TODO Auto-generated method stub
		return ToolBarBuilderTemplate.createToolBarBuilderTemplate(map1,map2);
	}
	public static GxtComponentControllerMetaNodeModel createFormPanelTemplate(
			String controllerMetaModelId, int leftValue, int rightValue, Map<String, Object> map2) {
		Map<String, Object> map1=configureMap1(controllerMetaModelId, leftValue, rightValue);
		return FormPanelBuilderTemplate.createFormPanelBuilderTemplate(map1,map2);				
		//return node;		
	}
	
	public static GxtComponentControllerMetaNodeModel createPanelInFormTemplate(
			String controllerMetaModelId, int leftValue, int rightValue,
			Map<String, Object> panelInFormMap2) {
		Map<String, Object> map1=configureMap1(controllerMetaModelId, leftValue, rightValue);
		return PanelInFormBuilderTemplate.createFormPanelBuilderTemplate(map1,panelInFormMap2);				
	}
	public static GxtComponentControllerMetaNodeModel createGridTemplate(
			String controllerMetaModelId, int leftValue, int rightValue, Map<String, Object> map2) {
		Map<String, Object> map1=configureMap1(controllerMetaModelId, leftValue, rightValue);
		return GridBuilderTemplate.createGridBuilderTemplate(map1,map2);	
	}
	

}
